<?php

namespace app\home\controller;

use think\Db;
use clt\Leftnav;
use think\Controller;
use controller\BasicHome;
use think\Request;
use think\Config;
use think\Debug;

class Common extends BasicHome{

    protected $pagesize,$changyan,$new_aid;

    public function _initialize()
    {
        parent::_initialize();
    }
    
    function __construct(Request $request = null)
    {
        parent::__construct($request);
    }
    
    public function _empty(){
        return $this->error('空操作，返回上次访问页面中...');
    }

    public function ck_auth($m, $id, $cid = 2){
        $member =  session('member');
        if(!$member){
            $this->error('请先登录', url('home/login/index'));
        }
        $member = $this->member->getOneDarry(['id' => session('member.id')]);

        switch(strtolower($m)){
                case 'courseware':
                        $model = $this->category->getValue(['id' => $cid], 'module');
                        break;
                case 'news':
                        $model = 'article';
                        break;
                default:
                        $model = $m;
        }
        $info = Db::name($model)->where(['id' => $id])->find();
        // halt($member['role']);
        if(!empty($info['readgroup']) && !in_array($member['role'], explode(',', $info['readgroup']))){
            $this->error('访问权限不足，请联系管理员');
        }
        $arr = (strtolower($m) == 'courseware') ? ['id' => $id, 'cid' => $cid] : ['id' => $id]; 
        $url = url('home/'.$m.'/detail', $arr);
        $this->success('成功', $url);
    }
}